home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef __CSAPP__
- #define __CSAPP__
-
- /* file CSApp.h Copyright (C) 1996, 1997 by John R. Montbriand. All Rights Reserved.
- callback skeleton application, definitions.
- Copyright (c) 1996, 1997 by John Montbriand. All Rights Reserved.
- Permission hereby granted for public use.
- Distribute freely in areas where the laws of copyright apply.
- USE AT YOUR OWN RISK.
- DO NOT DISTRIBUTE MODIFIED COPIES.
- Comments/questions/postcards* to the author at the address:
- John Montbriand
- P.O. Box. 1133
- Saskatoon Saskatchewan Canada
- S7K 3N2
- or by email at:
- tinyjohn@sk.sympatico.ca
- *if you mail a postcard, then I will provide you with technical support
- regarding questions you may have about this file.
- */
-
- #include <Types.h>
- #include <QuickDraw.h>
- #include <Menus.h>
- #include <Windows.h>
- #include <Dialogs.h>
- #include <AppleEvents.h>
-
- /* version of this interface */
- #define kCSAppVersion 1
-
-
- /* ASSORTED UTILITIES */
-
- /* TrapAvail returns true if the indicated trap is defined. */
- Boolean TrapAvail(unsigned short theTrap);
-
- /* GotReqParam checks the appleEvent to ensure all of the required
- parameters are present. */
- OSErr GotReqParam(const AppleEvent *apple_event);
-
-
-
-
- /* EDITING COMMANDS */
-
- /* standard edit menu items */
- #define iUndo 1
- #define iCut 3
- #define iCopy 4
- #define iPaste 5
- #define iClear 6
-
- /* DialogEdit is automatically called by CallEditCommand and you should only
- have to call it if you define your own EditDialogFunc. It calls DialogCut,
- DialogCopy, DialogPaste, or DialogDelete. */
- void DialogEdit(short itemno);
-
- /* CallEditCommand dispatches the editing command to the correct handler depending
- on windowKind field of the current front window. Either DialogEdit, the
- EditDialogFunc, or the EditWindowFunc will be called. */
- void CallEditCommand(short editcmd);
-
-
-
-
- /* MAIN DRIVER ROUTINES */
-
- /* OpenCSApp does all of the necessary initialization required for macintosh
- applications. stack_kilobytes should be set to the number of additional kilobytes
- you want over the default stack size, and masterblocks is the number of master
- pointer blocks to be allocated */
- OSErr OpenCSApp(long stack_kilobytes, long masterblocks);
-
- /* CSAppEvent does all of the event handling for the event record parameter
- calling any of the callbacks below. Normally, you do not have to call CSAppEvent
- as RunCSApp calls it for you, however, if you collect events yourself you
- can pass the event record to CSAppEvent after you are done with it. */
- void CSAppEvent(EventRecord *ev);
-
- /* RunCSApp calls GetNextEvent or WaitNextEvent (depending on what is available)
- and passes the resulting event record to CSAppEvent. the result value is
- the value returned by GetNextEvent or WaitNextEvent. NOTE: CSAppEvent
- is called for nullEvents too. */
- Boolean RunCSApp(long sleep);
-
- /* CSAppGetEvent calls either GetNextEvent or WaitNextEvent depending on what
- is defined passing the event record to the routine and returns the result.
- RunCSApp calls CSAppGetEvent before calling CSAppEvent. You can
- call CSAppGetEvent and CSAppEvent yourself if you want to put some additional
- processing between these calls. */
- Boolean CSAppGetEvent(EventRecord *ev, long sleep);
-
- /* CloseCSApp closes the application. Presently, it only calls ExitToShell(). This
- routine never returns. */
- void CloseCSApp(void);
-
-
-
-
- /* MENU COMMANDS */
-
- /* MenuResetFunc is called just before MenuSelect or MenuKey providing your application
- a chance to enable the menus correctly for the present program state. */
- typedef void (*MenuResetFunc)(void);
-
- /* MenuHandlerFunc is called after MenuSelect or MenuKey if a menu selection has
- been made. menu and item will describe the selection, modifiers is the modifiers
- flags from the event record and the_menu is a handle to the menu. */
- typedef void (*MenuHandlerFunc)(short menu, short item, short modifiers, MenuHandle the_menu);
-
-
- /* SetMenuFunctions sets the reset and handler function for all menu commands. if menubarID
- is not zero, then the menu bar is set to the indicated menu bar resource read from
- the application's resource fork. */
- OSErr SetMenuFunctions(short menubarID, MenuResetFunc reset, MenuHandlerFunc handler);
-
-
-
-
- /* DIALOG COMMANDS */
-
- /* DialogEventFunc is called for dialog windows before IsDialogEvent or DialogSelect
- is called. This allows your application time to do any special event filtering
- required for dialogs. */
- typedef void (*DialogEventFunc)(DialogPtr dialog, EventRecord *ev);
-
- /* DialogHitFunc is called for dialogs whenever DialogSelect returns true. itemhit
- is the item number returned by DialogSelect, and modifiers is the modifiers
- field copied from the event record. */
- typedef void (*DialogHitFunc)(DialogPtr dialog, short itemhit, short modifiers);
-
- /* EditDialogFunc is called by CallEditCommand when the frontmost window
- is a dialog window. For most purposes, you should call DialogEdit from
- your edit function. */
- typedef void (*EditDialogFunc)(DialogPtr dialog, short editcmd);
-
-
- /* SetDialogFunctions sets the functions used for handling dialog events. If you
- set the edit parameter to NULL, then DialogEdit will be called for edit commands
- destined for dialog windows. Any one or all of the parameters may be NULL. */
- void SetDialogFunctions(DialogEventFunc evtproc, DialogHitFunc hitproc, EditDialogFunc edit);
-
- /* DialogAppendItems appends the DITL resource items to the bottom of the dialog
- window resizing the window as appropriate. *first_item is set to the index
- of the first item added to the dialog. If the new dialog routines are present
- they are used, otherwise older glue code is used to append the items. */
- OSErr DialogAppendItems(DialogPtr dialog, short id, short *first_item);
-
-
-
- /* WINDOW COMMANDS */
-
- /* CloseWindowFunc is called when TrackGoAway returns true for a window. */
- typedef void (*CloseWindowFunc)(WindowPtr window);
-
- /* GrowWindowFunc is called when the FindWindow returns the inGrow result code.
- where is the mouse position in global coordinates, and modifiers is copied from
- the event record's modifiers field. */
- typedef void (*GrowWindowFunc)(WindowPtr window, Point where, short modifiers);
-
- /* ZoomWindowFunc is called when FindWindow returns inZoomIn or inZoomOut. partcode
- is either inZoomIn or inZoomOut, and modifiers is copied from the event record's
- modifiers field. */
- typedef void (*ZoomWindowFunc)(WindowPtr window, short partcode, short modifiers);
-
- /* ClickWindowFunc is called whenever a mousedown occurs in a window's content
- area. where is the mouse location in local coordinates, count is the double-click
- count measured using GetDblTime and modifiers is copied from the event record's
- modifiers field */
- typedef void (*ClickWindowFunc)(WindowPtr window, Point where, short count, short modifiers);
-
- /* ActivateWindowFunc is called whenever a window receives an activate event. activate
- is true if the window is becoming active. */
- typedef void (*ActivateWindowFunc)(WindowPtr window, Boolean activate);
-
- /* UpdateWindowFunc is called for update events directed to a window. you must call
- BeginUpdate and EndUpdate yourself */
- typedef void (*UpdateWindowFunc)(WindowPtr window);
-
- /* EditWindowFunc is called by CallEditCommand whenever a window is frontmost.
- editcmd will be one of the edit menu items defined above. */
- typedef void (*EditWindowFunc)(WindowPtr window, short editcmd);
-
-
- /* SetWindowManipulators sets the window callback routines used by the application for
- manipulating the window. Any or all of the parameters may be set to NULL depending
- on what functionality is required. */
- void SetWindowManipulators(CloseWindowFunc close, GrowWindowFunc grow, ZoomWindowFunc zoom);
-
- /* SetWindowInteraction sets the window callback routines used by the application for
- interacting with the contents of the window. Any or all of the parameters may be
- set to NULL depending on what functionality is required. */
- void SetWindowInteraction(ClickWindowFunc click, EditWindowFunc edit);
-
- /* SetWindowRedraw sets the window callback routines used by the application for
- drawing the contents of the window. Any or all of the parameters may be
- set to NULL depending on what functionality is required. */
- void SetWindowRedraw(ActivateWindowFunc activate, UpdateWindowFunc update);
-
-
- /* SafeCloseWindow and SafeDisposeWindow are replacements for the standard
- CloseWindow and DisposeWindow routines. Before a window is removed from the
- screen, if it is the active window, the ActivateWindowFunc is called with active
- set to false. */
- void SafeCloseWindow(WindowPtr window);
- void SafeDisposeWindow(WindowPtr window);
-
- /* ZoomWindowToSize zooms the window to a particular size. On multiple monitor
- systems the window is zoomed to the display intersecting with the largest area of
- the window. */
- void ZoomWindowToSize(WindowPtr window, short width, short height, short zoomDir);
-
-
-
- /* KEYBOARD INPUT COMMAND */
-
- /* KeyboardFunc is called for keyboard events. key will be the ascii code
- and ev is the event record. */
- typedef void (*KeyboardFunc)(char key, EventRecord *ev);
-
-
- /* SetKeyboardHook sets the keyboard hook for the application. if no keyboard
- hook is required, then you can set the parameter to NULL. */
- void SetKeyboardHook(KeyboardFunc keys);
-
-
-
-
- /* MISCELLANEOUS COMMANDS */
-
- /* DiskInsertFunc will be called for disk inserted events. */
- typedef void (*DiskInsertFunc)(EventRecord *ev);
-
- /* EventHookFunc is called at the beginning of CSAppEvent allowing your application
- to filter events before they are processed through the callbacks. if the function
- returns true, then no further event processing happens, otherwise the event is
- passed through the callbacks. You can also use this routine to implement cursor
- switching. */
- typedef Boolean (*EventHookFunc)(EventRecord *ev);
-
- /* SwitcherFunc is called whenever an application switches from the foreground to the
- background or vise versa. If switching_in is true, then the application is
- switching into the forground. */
- typedef void (*SwitcherFunc)(Boolean switching_in);
-
-
- /* SetMiscFunctions sets the callbacks for the above functions. Any or all of the
- parameters may be NULL depending one what routines are provided. */
- void SetMiscFunctions(DiskInsertFunc disk, EventHookFunc hook, SwitcherFunc switcher);
-
-
-
-
- /* MOVEABLE MODAL WINDOW COMMANDS */
-
- /* MMHookFunc is called whenever the application's moveable modal dialog
- state changes from on to off. mmactive will be true if a moveable modal
- dialog is now present on the screen. This allows your application to disable
- menus, et cetera. */
- typedef void (*MMHookFunc)(Boolean mmactive); /* called with mm state changes */
-
- /* SetMMHookProc sets the moveable modal mode switch hook that is called whenever
- the application's moveable modal state switches from either on to off or off to on. */
- void SetMMHookProc(MMHookFunc mmhook);
-
- /* GetMMWindow returns a pointer to the current moveable modal window, or NULL
- if there is no current moveable modal window */
- WindowPtr GetMMWindow(void);
-
- /* SetMMWindow returns a pointer to the last moveable modal window and sets the
- new moveable modal window to target. you can use combinations of GetMMWindow
- and SetMMWindow together to save and restore the MM state and thereby nest
- moveable modal windows. */
- WindowPtr SetMMWindow(WindowPtr target);
-
- #endif
-